<template>
  <div class="app-container1">

    <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
      <el-form-item label="业务单号" prop="orderCode">
        <el-input
          v-model="queryParams.orderCode"
          placeholder="请输入业务单号"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="任务提交人" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入任务提交人"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审批结果" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="审批结果"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="完成时间">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="tastList">
      <el-table-column label="序号" align="center" type="index"/>
      <el-table-column label="业务单号" align="center" prop="orderCode"/>
      <el-table-column label="业务流程名称" align="center" prop="processDefinitionName"/>
      <el-table-column label="提交人员" align="center" prop="name"/>
      <el-table-column label="提交时间" align="center" prop="startTime"/>
      <el-table-column label="业务流程key" align="center" prop="businessKey"/>
      <el-table-column label="业务处理角色" align="center" prop="taskNodeName"/>
      <el-table-column label="审批结果" align="center" prop="FormProperty_agree"/>
      <el-table-column label="审批意见" align="center" prop="FormProperty_remark"/>
      <el-table-column label="审批时间" align="center" prop="createTime"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleCheck(scope.row)"
          >详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 审批对话框 -->
    <el-dialog :title="title" :visible.sync="open" v-if="open" width="500px" append-to-body>
      <operationalForm :businessKey="businessKey" v-if="'yyxq_audit'==definitionKey"/>

      <el-form :model="form" ref="form" label-width="100px" class="demo-dynamic">
        <el-form-item
          v-for="(domain, index) in form.formData"
          :label="domain.controlLable"
          :key="task"
        >
          <el-radio-group v-model="domain.controlValue" v-if="'radio'==domain.controlType">
            <el-radio v-for="(defaults,indexd) in domain.controlDefault.split('--__--')"
                      :label=indexd
                      :key="indexd"
                      >{{defaults}}
            </el-radio>

          </el-radio-group>
          <el-input type="textarea" v-model="domain.controlValue" v-if="'textarea'==domain.controlType"
          ></el-input>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" :disabled="isDisabled" :loading="loadingBut">{{loadingButText}}</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

  import {historyInfoData} from "@/api/activiti/historyFormdata";
  import {getOperationalInfo2} from "@/api/operation";
  import {getAttendanceStatistics} from "@/api/job/attendance/attendanceApi";
  import {dateFormatter} from "@/api/tool/DateUtil";
  export default {
    name: "myHistory",
    data() {
      return {
        isDisabled:false,
        loadingBut:false,
        loadingButText:'确定',
        id:'',
        definitionKey: '',
        businessKey: '',
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        statusOptions:[
          {dictLabel:"同意",dictValue:1}, {dictLabel:"不同意",dictValue:0}
        ],
        // 总条数
        total: 0,
        // 列表数据
        tastList: [],
        dateRange: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
        },
        // 表单参数
        form: {
          formData:[]
        },
        // 表单校验
        rules: {}
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRange = [];
        this.resetForm("queryForm");
        this.handleQuery();
      },
      /** 查询请假列表 */
      getList() {
        this.loading = true;
        historyInfoData(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.tastList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },

      // 表单重置
      reset() {
        this.definitionKey = '',
          this.businessKey = '',
          this.form = {
            formData:[],
          };
        this.resetForm("form");
      },
      /** 详情按钮操作 */
      handleCheck(row){
        const id = row.businessKey.split('_')[1];
        let name =row.businessKey.split('_')[0];
        if(name=='yyxq'){
          let enableSchemeId = null;
          getOperationalInfo2(id).then(res=>{
            const status =res.data.status;
            const params = { id: id,status:status, handleType: 'view'};
            this.$router.push({ path:"/plan/employeeDetail", query: params });
          })
        }else if(name=='lsgkq'){
          getAttendanceStatistics(id).then(response => {
            let orderCode =response.data.orderCode;
            let workTime =response.data.workTime;
            workTime=dateFormatter(workTime);
            this.$router.push({path:"/personnel/attendance/attendanceGroupDetail",query:{workTime:workTime,orderCode:orderCode}});
          });

        }

      },
    }
  };
</script>
